import http from '@/api/request'
import type { OaWorkflowStatus, UserTask } from '@/types/workflow'

/**
 * 获取日志（包括审批记录）
 * @param formId 
 */
export const getTaskLog =  async (formId:any)=>{
    const result =  await http.get<UserTask[],string>('/usertask/getUserTaskLog',{
        fid:formId
    })
    return {
        log:result.data,
        summary:result.param1
    }
}

/**
 * 
 * @param taskId 任务id
 * @returns  返回任务以及状态
 */
export const getTask = async (taskId:any)=>{
     const result = http.get<UserTask,OaWorkflowStatus>('/usertask/get',{
        taskId
    })
    return result;
}

/**
 * 完结
 */
export const finishTask = async (taskId:any)=>{
    const result = http.post<string>('/usertask/finish',{
       taskId
   })
   return result;
}

export const getToReadList = async (key:string)=>{
    const result =  await http.get<UserTask[]>('/usertask/toRead?key='+key);   
    return result.data;
}


export const getToReadCount = async ()=>{
    const result =  await http.get<number>('/usertask/toReadCount?key=');   
    if(result.data){
        return result.data
    }else{
        return 0;
    }
}


export const getTodoCount = async ()=>{
    const result =  await http.get<number>('/usertask/todoCount?key=');   
    if(result.data){
        return result.data
    }else{
        return 0;
    }
}


export const getRedirectCount = async ()=>{
    const result =  await http.get<number>('/usertask/redirectCount?title=');   
    if(result.data){
        return result.data
    }else{
        return 0;
    }
}


